    #include "regdef.h"
	.set noreorder
	.set volatile
	.set noat
	.set nomacro
	.arch sws
	.set sws_start
	.section	.text1.slave_omp2ath_run_stack,"ax",@progbits
	.align 4
	.globl slave_omp2ath_run_stack
	.ent slave_omp2ath_run_stack
$slave_omp2ath_run_stack..ng:
slave_omp2ath_run_stack:
    ldi  sp, -64(sp)
    stl  fp, 0(sp)
    stl  ra, 8(sp)
    ldi  fp, 0(sp)
    ldi  sp, 0(a2)
    ldi  t12, 0(a0)
    ldi  a0, 0(a1)
    jmp  ra, t12, 0
    .align 4
    ldi  sp, 64(fp)
    ldl  ra, 8(fp)
    ldl  fp, 0(fp)
    jmp  zero, ra, 0
    .end slave_omp2ath_run_stack
#define ASM_TASKSERVER
#ifdef ASM_TASKSERVER
	.section	.text1.slave_omp2ath_waiting_for_task,"ax",@progbits
	.align 4
	.globl slave_omp2ath_waiting_for_task
	.ent slave_omp2ath_waiting_for_task
$slave_omp2ath_waiting_for_task..ng:
slave_omp2ath_waiting_for_task:
    ldih gp, 0(t12) !gpdisp!1
    ldi  gp, 0(gp)  !gpdisp!1

    ldi  sp, -128(sp)
    stl  fp,   0(sp)
    stl  s0,   8(sp)
    stl  s1,  16(sp)
    stl  s2,  24(sp)
    stl  s3,  32(sp)
    stl  s4,  40(sp)
    stl  s5,  48(sp)
    stl  ra,  56(sp)

#define pen   s0
    rcsr pen, 0
    and  pen, 63, pen
#define args  s1
    ldih args, __omp2ath_args($31)  !ldmhigh
    ldi  args, __omp2ath_args(args) !ldmlow
#define reply s2
    ldih reply, __omp2ath_spawn_reply($31)   !ldmhigh
    ldi  reply, __omp2ath_spawn_reply(reply) !ldmlow
#define mask  s3
    ldi  mask, 0xff
#define ldmstack s4
    ldih ldmstack, 2
    ldi  ldmstack, -64(ldmstack)
#define privstack s5
    rcsr  t0, 0xc4
    ldih  privstack, __omp2ath_priv_stack(t0)        !tlshigh
    ldi   privstack, __omp2ath_priv_stack(privstack) !tlslow
    ldi   t0, 1
    sll   t0, 24, t0
    addl  privstack, t0, privstack
    //72(sp): desc高段, clobber: t1,t0
    sll  reply, 32, t1 //t1=reply<<32
    or   reply, t1, t0 //t0=reply<<32 | reply
    ldi  t0, 8(t0)     //t0=reply<<32 | reply+8
    ldi  t1, 255       //t1=0xff
    sll  t1, 24, t1    //t1=0xff<<24
    or   t1, t0, t0    //t0=reply<<32 | 0xff<<24 | reply+8
    stl  t0, 72(sp)

    //64(sp): desc低段, clobber t0
    ldi t0, 0x60       //t0=0x60
    sll  t0, 56, t0    //t0=0x60<<56
    ldi  t0, 24(t0)    //t0=(0x60<<56) + sizeof(args)
    stl  t0, 64(sp)
    //循环前同步
    sync mask
    synr mask

$Lloop_start:
    //其他从核不等任务
    bne s0, $Lothers_wait
$Lpe0_waitpc:
    //等待任务
    ldl  t12, 0(args)
    beq  t12, $Lpe0_waitpc
    //广播任务
    vldd $32, 64(sp)
    rma  $32, args, args
$Lothers_wait:
    //while reply == 0
    ldw  t0, 0(reply)
    beq  t0, $Lothers_wait
    
    //全核组同步
    memb
    sync mask
    synr mask
    
    //回答字清零
    stw  zero, 0(reply)
    ldl  t12, 0(args)
    //fn=-1，退出
    ldi  t1, 1(t12)
    beq  t1, $Lexit
#define dev t0
    ldl dev, 16(args)
    ldi fp, 0(sp)

    //dev=0, ldm栈
    seleq dev, ldmstack, sp, sp

    //dev=1, priv栈
    ldi   t1, -1(dev)
    seleq t1, privstack, sp, sp
#undef dev
    //ldih t2, __omp2ath_cntrs($31)   !ldmhigh
    //ldi  t2, __omp2ath_cntrs(t2) !ldmlow
    //vldd  $33, 0(t2)
    //rcsr  $32,   0x27
    //vinsf $32, $32, 7, $32
    //rcsr  $32,   0x26
    //vinsf $32, $32, 6, $32
    //rcsr  $32,   0x25
    //vinsf $32, $32, 5, $32
    //rcsr  $32,   0x24
    //vinsf $32, $32, 4, $32
    //rcsr  $32,   0x23
    //vinsf $32, $32, 3, $32
    //rcsr  $32,   0x22
    //vinsf $32, $32, 2, $32
    //rcsr  $32,   0x21
    //vinsf $32, $32, 1, $32
    //rcsr  $32,   0x20
    //vsubl $33, $32, $32
    //vstd  $32, 0(t2)
    
    //fn(dat)
    ldl   a0, 8(args)    
    jmp   ra, t12, 0x0

    //恢复现场
    ldih gp, 0(ra) !gpdisp!2
    ldi  gp, 0(gp) !gpdisp!2
    ldi  sp, 0(fp)

    //刷从核cache
    ldl  t12, slave_flush_slave_cache(gp) !literal
    jmp  ra, t12, 0x0
    ldih gp, 0(ra) !gpdisp!3
    ldi  gp, 0(gp) !gpdisp!3
    
    //ldih t2, __omp2ath_cntrs($31)   !ldmhigh
    //ldi  t2, __omp2ath_cntrs(t2) !ldmlow
    //vldd  $33, 0(t2)
    //rcsr  $32,   0x27
    //vinsf $32, $32, 7, $32
    //rcsr  $32,   0x26
    //vinsf $32, $32, 6, $32
    //rcsr  $32,   0x25
    //vinsf $32, $32, 5, $32
    //rcsr  $32,   0x24
    //vinsf $32, $32, 4, $32
    //rcsr  $32,   0x23
    //vinsf $32, $32, 3, $32
    //rcsr  $32,   0x22
    //vinsf $32, $32, 2, $32
    //rcsr  $32,   0x21
    //vinsf $32, $32, 1, $32
    //rcsr  $32,   0x20

    //vaddl $33, $32, $32
    //vstd  $32, 0(t2)
    
    //同步，所有从核执行完成
    sync  mask
    synr  mask
    stl  zero, 0(args)
    br   zero, $Lloop_start
$Lexit:
    sync  mask
    synr  mask
    stl  zero, 0(args)

    ldl  fp,   0(sp)
    ldl  s0,   8(sp)
    ldl  s1,  16(sp)
    ldl  s2,  24(sp)
    ldl  s3,  32(sp)
    ldl  s4,  40(sp)
    ldl  s5,  48(sp)
    ldl  ra,  56(sp)
    ldi  sp, 128(sp)
    jmp  zero, ra, 0x1
#undef pen
#undef args
#undef reply
#undef mask
    .end slave_omp2ath_waiting_for_task

#undef zero
	.globl __omp2ath_priv_stack
	.section	.slave_tls,"aw",@progbits
	.type	__omp2ath_priv_stack, @object
	.size	__omp2ath_priv_stack, 16777216
__omp2ath_priv_stack:
	.zero	16777216
	.globl __omp2ath_spawn_reply
	.section	.ldm
	.align 3
	.type	__omp2ath_spawn_reply, @object
	.size	__omp2ath_spawn_reply, 16
__omp2ath_spawn_reply:
	.zero	16
	.globl __omp2ath_args
	.align 3
	.type	__omp2ath_args, @object
	.size	__omp2ath_args, 24
__omp2ath_args:
	.quad	0
	.quad	0
	.quad	-1
	.globl __omp2ath_cntrs
	.align 6
	.type	__omp2ath_cntrs, @object
	.size	__omp2ath_cntrs, 64
__omp2ath_cntrs:
    .zero   64

	.ident	"GCC: (GNU) 7.1.0 20170502 (swgcc-1307 Committer: yangt <yangt@email.email> by comp9 at localhost.localdomain on Thu Jul 22 08:26:01 CST 2021)"
	.section	.note.GNU-stack,"",@progbits
#endif
